package com.hackerrank.challenges.clickomania;

import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Solution {
	/* Head ends here */
	private static class Point {
		int r, c, count;
		public Point(int r, int c, int count) {
			this.r = r;
			this.c = c;
			this.count = count;
		}
		public String toString() {
			return r + " " + c;
		}
	}
	private static void process(int r, int c, Queue<Integer> qr, Queue<Integer> qc, int gns, char g[][], char color, int gn[][]) {
		if(r < 0 || r >= g.length || c < 0 || c >= g[0].length)
			return;
		if(g[r][c] == color && gn[r][c] != gns) {
			qr.add(r);
			qc.add(c);
		}
	}
	private static int group(char g[][], int gn[][], int r, int c, int gns) {
		int count = 0;
		Queue<Integer> qr = new LinkedList<Integer>(), qc = new LinkedList<Integer>();
		qr.add(r);
		qc.add(c);
		while(!qr.isEmpty()) {
			r = qr.poll();
			c = qc.poll();
			if(gn[r][c] == gns)
				continue;
			gn[r][c] = gns;
			count++;
			process(r - 1, c, qr, qc, gns, g, g[r][c], gn);
			process(r, c - 1, qr, qc, gns, g, g[r][c], gn);
			process(r, c + 1, qr, qc, gns, g, g[r][c], gn);
			process(r + 1, c, qr, qc, gns, g, g[r][c], gn);
		}
		return count;
	}
	private static Point getBestMove(char g[][], int tnb) {
		long t1 = System.currentTimeMillis();
		int gn[][] = new int[g.length][], ng = 0, mc = Integer.MAX_VALUE, mcr = -1, mcc = -1;
		for(int r = 0; r < g.length; r++)
			gn[r] = new int[g[r].length];
		for(int r = 0; r < g.length; r++) {
			for(int c = 0; c < g[r].length; c++) {
				if(g[r][c] == '-' || gn[r][c] > 0)
					continue;
				int nb = group(g, gn, r, c, ++ng);
				if(nb > 1) {
					// modify the grid
					char cg[][] = new char[g.length][];
					for(int cgr = 0; cgr < g.length; cgr++)
						cg[cgr] = new char[g[cgr].length];
					int tc = 0;
					for(int sc = 0; sc < g[0].length; sc++) {
						int tr = g.length;
						for(int sr = g.length - 1; sr >= 0; sr--)
							if(g[sr][sc] != '-' && gn[sr][sc] != ng)
								cg[--tr][tc] = g[sr][sc];
						if(tr < g.length) {
							for(--tr; tr >= 0; tr--)
								cg[tr][tc] = '-';
							tc++;
						}
					}
					for(;tc < cg[0].length; tc++)
						for(int tr = 0; tr < cg.length; tr++)
							cg[tr][tc] = '-';
					// get the best move again
					Point p = getBestMove(cg, tnb - nb);
					if(p.count < mc) {
						mc = p.count;
						mcr = r;
						mcc = c;
						if(mc == 0)
							return new Point(mcr, mcc, mc);
					}
				}
				if(System.currentTimeMillis() - t1 > 4000)
					break;
			}
			if(System.currentTimeMillis() - t1 > 4000)
				break;
		}
		if(mc == Integer.MAX_VALUE)
			return new Point(mcr, mcc, tnb);
		return new Point(mcr, mcc, mc);
	}
	static void nextMove(int x, int y, int color, String [] grid) {
		char g[][] = new char[grid.length][];
		int tnb = 0;
		for(int i = 0; i < grid.length; i++) {
			g[i] = grid[i].toCharArray();
			for(int j = 0; j < g[i].length; j++)
				if(g[i][j] != '-')
					tnb++;
		}
		System.out.println(getBestMove(g, tnb));
	}
	/* Tail starts here */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int y = in.nextInt();
		int k = in.nextInt();

		String grid[] = new String[x];

		for(int i = 0; i < x; i++) {
			grid[i] = in.next();
		}

		nextMove(x, y, k, grid);
	}
}
